/**
 * 工作流相关 API
 */

import { get, post, put, del } from '@/utils/request'
import type {
  WorkflowDefinition,
  CreateWorkflowRequest,
  UpdateWorkflowRequest,
  WorkflowValidationResult,
} from '@/types'

/**
 * 获取工作流列表
 */
export function getWorkflows(): Promise<WorkflowDefinition[]> {
  return get<WorkflowDefinition[]>('/api/Workflow')
}

/**
 * 根据 ID 获取工作流
 */
export function getWorkflowById(id: number): Promise<WorkflowDefinition> {
  return get<WorkflowDefinition>(`/api/Workflow/${id}`)
}

/**
 * 创建工作流
 */
export function createWorkflow(data: CreateWorkflowRequest): Promise<WorkflowDefinition> {
  return post<WorkflowDefinition>('/api/Workflow', data)
}

/**
 * 更新工作流
 */
export function updateWorkflow(
  id: number,
  data: UpdateWorkflowRequest
): Promise<WorkflowDefinition> {
  return put<WorkflowDefinition>(`/api/Workflow/${id}`, data)
}

/**
 * 删除工作流
 */
export function deleteWorkflow(id: number): Promise<void> {
  return del<void>(`/api/Workflow/${id}`)
}

/**
 * 验证工作流
 */
export function validateWorkflow(id: number): Promise<WorkflowValidationResult> {
  return post<WorkflowValidationResult>(`/api/Workflow/${id}/validate`)
}

/**
 * 启用工作流
 */
export function enableWorkflow(id: number): Promise<void> {
  return post<void>(`/api/Workflow/${id}/enable`)
}

/**
 * 禁用工作流
 */
export function disableWorkflow(id: number): Promise<void> {
  return post<void>(`/api/Workflow/${id}/disable`)
}
